<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.model');

/**
 * Component County Model
 */
class TaxibookingModelCounty extends JModel
{
	/**
	 * Item data
	 *
	 * @var object
	 */
	var $_item = null;

	/**
	 * Constructor
	 *
	 * @since 1.0
	 */
	function __construct()
	{
		parent::__construct();

		$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
		JArrayHelper::toInteger($cid, array(0));
		$this->setId($cid[0]);
	}

	/**
	 * Method to set the identifier
	 *
	 * @access	public
	 * @param	int item identifier
	 */
	function setId($id)
	{
		// Set item id and wipe data
		$this->_id	    = $id;
		$this->_item	= null;
	}

	/**
	 * Method to load item data
	 *
	 * @access	private
	 * @return	boolean	True on success
	 * @since	1.0
	 */
	function &getItem()
	{
            $query = 'SELECT *'
                    . ' FROM #__taxibooking_county'
                    . ' WHERE id = '.$this->_id
                    ;
            $this->_db->setQuery($query);
            $this->_item = $this->_db->loadObject();

            return $this->_item;
		
	}

	/**
	 * Method to store the item
	 *
	 * @access	public
	 * @return	boolean	True on success
	 * @since	1.0
	 */
	function store($data)
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
				
		$item  =& $this->getTable('taxibooking_county', '');
		$user	=& JFactory::getUser();
		
		// bind it to the table
		if (!$item->bind($data)) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}

		// sanitise id field
		$item->id = (int) $item->id;
		
		$nullDate	= $this->_db->getNullDate();

		// Are we saving from an item edit?
		if (!$item->id) {
			//get time and userid
			$item->created 			= gmdate('Y-m-d H:i:s');
			$item->created_by		= $user->get('id');
		}
		
		if (!$item->id) {
			$item->ordering = $item->getNextOrder();
		}
		
		// Make sure the data is valid
		if (!$item->check()) {
			$this->setError($item->getError());
			return false;
		}

		// Store it in the db
		if (!$item->store()) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}
		
		$this->_item	=& $item;
		

		return true;
	}

}
?>